﻿layui.use('form', function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery;

    //监听启用开关
    form.on('switch(swithEnable)', function (data) {
        $(data.elem).attr('type', 'hidden').val(this.checked ? 1 : 0);
    });

    //监听下拉开关
    form.on('switch(ParentModule)', function (data) {
        $(data.elem).attr('type', 'hidden').val(data.value);
    })

        //表单提交
    form.on('submit(submit)', function (data) {
        if (data.field.IsEnable != "1") {
            data.field.IsEnable = "0";
        }
            $.ajax({
                url: "/Module/UpdateModule",
                method: 'post',
                data: data.field,
                dataType: 'JSON',
                success: function (res) {
                    if (res.Success) {
                        //验证码效验成功之后提交到后台
                        layer.msg(res.msg, {
                            title: '提示框',
                            icon: 1,
                            time: 3000,
                            end: function () {
                                window.location.href = "/Module/Index";
                            }
                        });
                    }
                    else {
                        layer.alert(res.msg);

                    }
                },
                error: function (data) {

                }
            });
            return false;
        })
    
})